Skip to content

ManaPool: use Multiset for floatingMana#10824

Draft
Hanmac wants to merge 1 commit into
masterfrom
manaMultiSet
Draft

ManaPool: use Multiset for floatingMana#10824
Hanmac wants to merge 1 commit into
masterfrom
manaMultiSet

Conversation

@Hanmac
Copy link
Copy Markdown
Contributor

@Hanmac Hanmac commented Jun 1, 2026

Part of #10750

Store Mana in the ManaPool as {Mana => 3}

Copy link
Copy Markdown
Contributor

@tool4ever tool4ever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmn, presenting me with another tricky refactor:

  • Personally I'm somewhat skeptical the code really becomes cleaner by introducing these additional concepts into it

  • But more importantly I'm also concerned this could degrade performance on a heavy workload class...
    There seems to be way more filtering going on because you no longer store the color mapping - instead the HashMultiset will have lots of buckets based on the different Mana records

Sorry, but I'd prefer a second opinion here too before I can spend some time testing for regressions 🤔

@tool4ever tool4ever requested a review from tehdiplomat June 1, 2026 10:54
@Hanmac
Copy link
Copy Markdown
Contributor Author

Hanmac commented Jun 1, 2026

  • instead the HashMultiset will have lots of buckets based on the different Mana records

That shouldn't be much of a problem,
AbstractMapBasedMultiset does keep the total of the elements as extra variable.

https://github.com/google/guava/blob/a8e9533b499a446cccf7eff54e7775327fb119ec/android/guava/src/com/google/common/collect/AbstractMapBasedMultiset.java#L249-L251

so in case of {A => 1, B => 2, C => 3} it already knows the total size = 6

and right now, there shouldn't be too much filtering going on


if (manaList instanceof Multiset<Mana> manaSet) {
colors = manaSet.elementSet().stream().map(m -> MagicColor.Color.fromByte(m.getColor())).collect(Collectors.toSet());
floatingMana.addAll(manaSet);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one reason why i don't have multiple lists per color, is that i can't use
Multisets.removeOccurrences on them.

@tool4ever
Copy link
Copy Markdown
Contributor

I can try and check some more later this week but right now it looks like everyone (and their mother) wants me to review their stuff 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants